﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Menu
{
    class Program
    {
        static void Main(string[] args)
        {
            menu menu = new menu();
            menu.hienthimenu();

        }


    }
    //======================================Class nguoi==========================
    public class nguoi
    {
        //----------------------------------data---------------------------------
        private string hoten;
        private int namsinh;
        //---------------------------------hanhvi--------------------------------
        public nguoi()
        {
            hoten = "";
            namsinh = 0;
        }
        public nguoi(string _hten, int _nsinh)
        {
            hoten = _hten;
            namsinh = _nsinh;
        }
        //-----------------------------cac ham set-------------------------------
        public void set_hoten(string _hoten)
        {
            hoten = _hoten;
        }
        public void set_namsinh(int _namsinh)
        {
            namsinh = _namsinh;
        }
        //-----------------------------cac ham get-------------------------------
        public string get_hoten()
        {
            return hoten;
        }
        public int get_namsinh()
        {
            return namsinh;
        }
        //------------------nhap class nguoi-------------------------------------
        public void nhap_ng()
        {
            Console.Write("Ho ten: ");
            set_hoten(Console.ReadLine());
            Console.Write("Nam sinh: ");
            set_namsinh(Convert.ToInt32(Console.ReadLine()));

        }
        //----------------------hien thi class nguoi-----------------------------
        public void hienthi_ng()
        {
            Console.WriteLine("\nHo ten: \t" + get_hoten());
            Console.WriteLine("Nam sinh: \t" + get_namsinh());
        }
    }
    //=====================================Class sinhvien========================
    public class sinhvien : nguoi
    {
        //-------------------------data------------------------------------------
        private string masv;
        private float diem_toan, diem_ly, diem_hoa, diem_tb;


        //--------------------------hanhvi---------------------------------------
        public sinhvien()
        {

            masv = "";
            diem_toan = 0;
            diem_ly = 0;
            diem_hoa = 0;
            diem_tb = 0;
        }
        public sinhvien(string _masv, float _dtoan, float _dly, float _dhoa, float _dtb)
        {
            masv = _masv;
            diem_toan = _dtoan;
            diem_ly = _dly;
            diem_hoa = _dhoa;
            diem_tb = _dtb;
        }
        //-------------------------cac ham set-----------------------------------
        public void set_masv(string _masv)
        {
            masv = _masv;
        }
        public void set_dtoan(float _dtoan)
        {
            diem_toan = _dtoan;
        }
        public void set_dly(float _dly)
        {
            diem_ly = _dly;
        }
        public void set_dhoa(float _dhoa)
        {
            diem_hoa = _dhoa;
        }
        public void set_dtb(float _dtb)
        {
            diem_tb = _dtb;
        }
        //-------------------------cac ham get-----------------------------------
        public string get_masv()
        {
            return masv;
        }
        public float get_dtoan()
        {
            return diem_toan;
        }
        public float get_dly()
        {
            return diem_ly;
        }
        public float get_dhoa()
        {
            return diem_hoa;
        }
        public float get_dtb()
        {
            return diem_tb;
        }
        //--------------------------ham nhap class sinhvien----------------------
        public void nhapsv()
        {
            //Console.WriteLine("\nNhap vao thong tin sinh vien");

            base.nhap_ng();
            Console.Write("MaSV: ");
            set_masv(Console.ReadLine());
            Console.Write("Diem Toan: ");
            set_dtoan(Convert.ToSingle(Console.ReadLine()));
            Console.Write("Diem Ly: ");
            set_dly(Convert.ToSingle(Console.ReadLine()));
            Console.Write("Diem Hoa: ");
            set_dhoa(Convert.ToSingle(Console.ReadLine()));
            set_dtb((diem_toan + diem_ly + diem_hoa) / 3);
        }

        //-------------------------ham hien thi class sinhvien-------------------
        public void hienthisv()
        {
            base.hienthi_ng();
            Console.WriteLine("MaSV:     \t" + get_masv());
            Console.Write("Diem Toan: \t{0:F2}", get_dtoan());
            Console.Write(" Diem Ly: \t{0:F2}", get_dly());
            Console.WriteLine(" Diem Hoa: \t{0:F2}", get_dhoa());
            Console.WriteLine("Diem TB: \t{0:F2}", get_dtb());
        }
    }
    //========================================MENU================================
    public class menu
    {
        //---------------------------data-----------------------------------------
        ConsoleKeyInfo k;
        private int sosv, temp;
        private byte themsv;
        public sinhvien[] sv1, sv2, sv3, sv4, sv5, tb_tang, hon5, tim_ten, tim_msv, tim_xl;
        sinhvien svien = new sinhvien();


        //---------------------------hanh vi--------------------------------------
        public void csdl()
        {
            sosv = 0;
            themsv = 0;
            temp = 0;
        }
        //------------------------ham set-----------------------------------------
        public void set_sosv(int _sosv)
        {
            sosv = _sosv;
        }
        public void set_themsv(byte _themsv)
        {
            themsv = _themsv;
        }
        //------------------------ham get-----------------------------------------
        public int get_sosv()
        {
            return sosv;
        }
        public byte get_themsv()
        {
            return themsv;
        }
        //------------------------ham hien thi menu-------------------------------
        public void hienthimenu()
        {
            Console.Clear();
            for (int i = 1; i <= 3; i++) Console.WriteLine();
            Console.WriteLine("<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>");
            Console.WriteLine("\t\t\tCHUONG TRINH QUAN LY SINH VIEN");
            Console.WriteLine();
            Console.WriteLine("NHAN PHIM DE CHON CHUC NANG:");
            Console.WriteLine();
            Console.WriteLine("\t1.   NHAP THONG TIN SINH VIEN MOI");
            Console.WriteLine("\t2.   HIEN THI DANH SACH SINH VIEN");
            Console.WriteLine("\t3.   TIM MOT SINH VIEN");
            Console.WriteLine("\t4.   IMPORT & EXPORT FILE");
            Console.WriteLine("\tESC. THOAT CHUONG TRINH");
            Console.WriteLine("<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>");
            Console.WriteLine();

            Console.Write("NHAN PHIM: ");
            k = Console.ReadKey();


            switch (k.Key)
            {
                case (ConsoleKey.D1):
                    {

                        //-----Nhap thong tin sinh vien-----
                        menu_nhap();
                        break;
                    }
                case (ConsoleKey.D2):
                    {
                        //--------------------------------- HIEN THI----------------------------------------

                        menu2(); break;

                    }
                case (ConsoleKey.D3):
                    {
                        //-----------------------------------HAM TIM KIEM------------------------------------
                        menu3(); break;
                    }
                case (ConsoleKey.D4):
                    {
                        //------------------------------THAO TAC VOI TEP-----------------------------------------

                        menu4(); break;
                    }
                case (ConsoleKey.Escape):
                    {
                        Environment.Exit(0); break;
                    }
                default:
                    {
                        Console.WriteLine("  NHAP KHONG DUNG THU TU, XIN NHAP LAI!");
                        Console.ReadKey();
                        hienthimenu();
                        break;
                    }

            }
        }
        //---------------------------------------------HAM THUC HIEN MENU 2--------------------------------
        public void menu2()
        {
            ConsoleKeyInfo k1;
            menu_hthi();
            k1 = Console.ReadKey();
            switch (k1.Key)
            {
                case ConsoleKey.D1:
                    {
                        Console.Clear();
                        Console.WriteLine();
                        Console.WriteLine("\t\tDANH SACH SINH VIEN THEO THU TU NHAP");
                        hienthitatca();
                        Console.WriteLine("NHAN NUT BAT KI DE TRO LAI!");
                        Console.ReadKey();
                        menu2();
                        break;
                    }
                case ConsoleKey.D2:
                    {
                        Console.Clear();
                        Console.WriteLine();
                        Console.WriteLine("\t\tDANH SACH SINH VIEN THEO DIEM TB TANG DAN");
                        ht_tbtang();
                        Console.WriteLine("NHAN NUT BAT KI DE TRO LAI!");
                        Console.ReadKey();
                        menu2();
                        break;
                    }
                case ConsoleKey.D3:
                    {
                        Console.Clear();
                        Console.WriteLine();
                        Console.WriteLine("\t\tDANH SACH SINH VIEN CO DIEM 3 MON TREN 5");
                        Console.WriteLine();
                        ht_hon5();
                        Console.WriteLine();
                        Console.WriteLine("NHAN NUT BAT KI DE TRO LAI!");
                        Console.ReadKey();
                        menu2();
                        break;
                    }
                case ConsoleKey.D4: hienthimenu(); break;
                case ConsoleKey.Escape: Environment.Exit(0); break;
            }
        }
        //-----------------------ham hien thi tat ca danh sach sv-------------------
        public void hienthitatca()
        {

            for (int i = 0; i < sosv; i++)
            {
                Console.Write("\nSTT:         \t{0}", (i + 1));
                sv1[i].hienthisv();
                Console.WriteLine("\n----------------------");
            }
        }
        //----------------------ham hien thi danh sach chon loc----------------------
        public void ht_tbtang()
        {
            tb_tang = new sinhvien[sosv];
            sinhvien tbtg = new sinhvien();

            tb_tang = sv1;
            for (int i = 0; i < (sosv - 1); i++)
            {
                for (int j = i; j < sosv; j++)
                {
                    if (sv1[i].get_dtb() > sv1[j].get_dtb())
                    {
                        tbtg = tb_tang[i];
                        tb_tang[i] = tb_tang[j];
                        tb_tang[j] = tbtg;

                    }
                }
            }
            for (int i = 0; i < sosv; i++)
            {
                Console.Write("\nSTT:         \t{0}", (i + 1));
                tb_tang[i].hienthisv();
                Console.WriteLine("\n----------------------");
            }
        }
        public void ht_hon5()
        {
            hon5 = new sinhvien[sosv];
            hon5 = sv1;
            int dem = 0;
            for (int i = 0; i < sosv; i++)
            {
                if ((sv1[i].get_dtoan() >= 5) && (sv1[i].get_dly() >= 5) && (sv1[i].get_dhoa() >= 5))
                {
                    Console.Write("\nSTT:         \t{0}", (i + 1));
                    hon5[i].hienthisv();
                    Console.WriteLine("\n----------------------");
                    dem++;
                }
            }
            if (dem == 0) Console.WriteLine("KHONG CO SINH VIEN NAO!");
        }
        //-------------------------------HAM THUC HIEN MENU 3 --------------------------------------
        public void menu3()
        {
            ConsoleKeyInfo k1;
            menu_timkiem();
            k1 = Console.ReadKey();
            switch (k1.Key)
            {
                case ConsoleKey.D1:
                    {
                        Console.Clear();
                        Console.WriteLine();
                        Console.WriteLine("\t\tTIM KIEM THEO TEN");
                        t_ten();

                        Console.WriteLine("NHAN NUT BAT KI DE TRO LAI!");
                        Console.ReadKey();
                        menu3();
                        break;
                    }
                case ConsoleKey.D2:
                    {
                        Console.Clear();
                        Console.WriteLine();
                        Console.WriteLine("\t\tTIM KIEM THEO MSSV");
                        t_msv();
                        Console.WriteLine("NHAN NUT BAT KI DE TRO LAI!");
                        Console.ReadKey();
                        menu3();
                        break;
                    }
                case ConsoleKey.D3:
                    {
                        Console.Clear();
                        Console.WriteLine();
                        Console.WriteLine("\t\tTIM KIEM THEO XEP LOAI DIEM TB");
                        menu_tim_xl();

                        Console.WriteLine("NHAN NUT BAT KI DE TRO LAI!");
                        Console.ReadKey();
                        menu3();
                        break;
                    }
                case ConsoleKey.D4: hienthimenu(); break;
                case ConsoleKey.D5: Environment.Exit(0); break;
                default:
                    {
                        Console.WriteLine("KHONG DUNG KI TU, XIN NHAP LAI!");
                        Console.ReadKey();
                        menu3();
                        break;
                    }
            }
        }
        public void menu4()
        {
            ConsoleKeyInfo k2;
            menu_xuatnhap();
            k2 = Console.ReadKey();
            switch (k2.Key)
            {
                case ConsoleKey.D1:
                    {
                        Console.Clear();
                        Console.WriteLine();
                        Console.WriteLine("\t\tEXPORT FILE");
                        ghi_file();

                        Console.WriteLine("NHAN NUT BAT KI DE TRO LAI!");
                        Console.ReadKey();
                        menu4();
                        break;
                    }
                case ConsoleKey.D2:
                    {
                        Console.Clear();
                        Console.WriteLine();
                        Console.WriteLine("\t\tIMPORT FILE");
                        Console.WriteLine();
                        doc_file();
                        Console.WriteLine("NHAN NUT BAT KI DE TRO LAI!");
                        Console.ReadKey();
                        menu4();
                        break;
                    }
                case ConsoleKey.D3:
                    {
                        hienthimenu();
                        break;
                    }
                case ConsoleKey.Escape: Environment.Exit(0); break;
                default:
                    {
                        Console.WriteLine("KHONG DUNG KI TU, XIN NHAP LAI!");
                        Console.ReadKey();
                        menu4();
                        break;
                    }
            }
        }
        //-------------------------------MENU NHAP-----------------------------
        public void menu_nhap()
        {
            Console.Clear();
            Console.WriteLine();
            Console.WriteLine("\t\tNHAP THONG TIN VAO CDSL");
            Console.WriteLine();
            Console.WriteLine("CHUC NANG NOI BAT CUA CHUONG TRINH LA CHO PHEP NHAP VAO CSDL ");
            Console.WriteLine("NHUNG THONG TIN DA CO SAN TU NHUNG TAP TIN DO CHUONG TRINH TAO RA TU TRUOC");
            Console.WriteLine("DONG THOI VOI VIEC NHAP THU CONG TAO RA SU LINH HOAT TRONG VIEC NHAP DU LIEU!");
            Console.WriteLine();
            Console.WriteLine("NHAN PHIM DE CHON CHUC NANG:");
            Console.WriteLine();
            Console.WriteLine("\t1.     NHAP THONG TIN TU FILE");
            Console.WriteLine("\t2.     NHAP THU CONG");
            Console.WriteLine("\t3.     TRO LAI MENU CHINH");
            Console.WriteLine("\tESC.   THOAT CHUONG TRINH");
            ConsoleKeyInfo k5;
            k5 = Console.ReadKey();
            switch (k5.Key)
            {
                case ConsoleKey.D1:
                    {
                        string name, filePath;
                        Console.Clear();
                        Console.WriteLine();
                        Console.WriteLine("\t\tIMPORT FILE");
                        Console.WriteLine();
                        Console.WriteLine("CHU Y: CHI CO THE NHAP THEM THONG TIN DUOI DANG DUOI '.ttd' VA NAM TRONG THU MUC GOC D:\\\\");
                        Console.WriteLine("MOI BAN KIEM TRA TRUOC KHI NHAP!");
                        Console.WriteLine();
                        Console.Write("NHAP TEN FILE: ");
                        name = Console.ReadLine();
                        filePath = "D:\\" + name + ".ttd";
                        if (File.Exists(filePath))
                        {
                            Console.Clear();
                            Console.WriteLine("\t\tNOI DUNG FILE " + filePath + " !");
                            Console.WriteLine();
                            int i = 0, temp, themsv;
                            temp = sosv;
                            sv4 = new sinhvien[10000];
                            using (StreamReader sr = File.OpenText(filePath))
                            {
                                string hoten, msv, nsinh, dtoan, dly, dhoa, dtb;
                                while
                                       ((hoten = sr.ReadLine()) != null &&
                                        (msv = sr.ReadLine()) != null &&
                                        (nsinh = sr.ReadLine()) != null &&
                                        (dtoan = sr.ReadLine()) != null &&
                                        (dly = sr.ReadLine()) != null &&
                                        (dhoa = sr.ReadLine()) != null &&
                                        (dtb = sr.ReadLine()) != null)
                                {
                                    sv4[i] = new sinhvien();
                                    sv4[i].set_hoten(hoten);
                                    sv4[i].set_namsinh(int.Parse(nsinh));
                                    sv4[i].set_masv(msv);
                                    sv4[i].set_dtoan(float.Parse(dtoan));
                                    sv4[i].set_dly(float.Parse(dly));
                                    sv4[i].set_dhoa(float.Parse(dhoa));
                                    sv4[i].set_dtb(float.Parse(dtb));
                                    i++;
                                }
                                themsv = i;
                                Console.WriteLine();
                                Console.WriteLine("NHAP THEM THANH CONG " + i + " SINH VIEN VAO CSDL!");
                                Console.WriteLine();
                                sr.Close();
                                sv5 = new sinhvien[sosv += themsv];

                                for (int z = 0; z < temp; z++)
                                {
                                    sv5[z] = sv1[z];
                                }
                                i = 0;
                                for (int j = temp; j < sosv; j++)
                                {
                                    sv5[j] = sv4[i]; i++;
                                }
                                sv1 = new sinhvien[sosv];
                                for (int t = 0; t < sosv; t++)
                                {
                                    sv1[t] = sv5[t];
                                }
                            }
                        }
                        else
                        {
                            Console.Clear();
                            Console.WriteLine();
                            Console.WriteLine("\t\tFILE KHONG TON TAI TREN THU MUC GOC!!");
                            Console.WriteLine();
                            Console.WriteLine("\tNHAN 1. NHAP LAI");
                            Console.WriteLine("\tNHAN 2. TRO LAI");
                            ConsoleKeyInfo k4 = Console.ReadKey();
                            switch (k4.Key)
                            {
                                case ConsoleKey.D1:
                                    {
                                        doc_file();
                                        break;
                                    }
                                case ConsoleKey.D2:
                                    {
                                        hienthimenu();
                                        break;
                                    }
                            }
                        }

                        Console.WriteLine("NHAN NUT BAT KI DE TRO LAI!");
                        Console.ReadKey();
                        hienthimenu();
                        break;
                    }
                case ConsoleKey.D2:
                    {
                        temp = sosv;
                        Console.Write("\nTRONG DU LIEU DANG CO " + sosv + " SINH VIEN. NHAP THEM SO SINH VIEN: ");
                        set_themsv(Convert.ToByte(Console.ReadLine()));

                        sv2 = new sinhvien[sosv += themsv];
                        if (themsv != 0)
                        {
                            for (int i = 0; i < temp; i++)
                            {
                                sv2[i] = sv1[i];
                            }
                            for (int i = temp; i < sosv; i++)
                            {
                                Console.WriteLine("NHAP THONG TIN CHO SINH VEN THU: " + (i + 1));
                                sv2[i] = new sinhvien();
                                sv2[i].nhapsv();

                            }
                        }
                        else
                        {
                            for (int i = 0; i < temp; i++)
                            {
                                sv2[i] = sv1[i];
                            }
                        }
                        sv1 = new sinhvien[sosv];
                        for (int i = 0; i < sosv; i++)
                        {
                            sv1[i] = sv2[i];

                        }
                        Console.WriteLine("NHAP DU LIEU THANH CONG!! NHAN PHIM BAT KI DE TIEP TUC!");
                        Console.ReadKey();
                        Console.Clear();
                        hienthimenu();
                        break;
                    }
                case ConsoleKey.D3:
                    {
                        Console.Clear();
                        hienthimenu();
                        break;
                    }
                case ConsoleKey.Escape:
                    {
                        Environment.Exit(0);
                        break;
                    }
                default:
                    {
                        Console.WriteLine("  NHAP KHONG DUNG THU TU, XIN NHAP LAI!");
                        Console.ReadKey();
                        hienthimenu();
                        break;
                    }
            }
        }
        //---------------------ham tim kiem theo ten----------------------------
        public void t_ten()
        {
            tim_ten = new sinhvien[sosv];
            sinhvien t_ten = new sinhvien();
            string ten;
            int dem = 0;
            Console.Write("NHAP VAO TEN SINH VIEN: ");
            ten = Console.ReadLine();
            for (int i = 0; i < sosv; i++)
            {
                if (ten == sv1[i].get_hoten())
                {
                    Console.Write("\nSTT:         \t{0}", (i + 1));
                    sv1[i].hienthisv();
                    Console.WriteLine("\n----------------------");
                    dem++;
                }
            }
            Console.WriteLine();
            if (dem == 0) Console.WriteLine("KHONG CO SINH VIEN NAO!");
            Console.WriteLine();
        }
        //---------------------ham tim kiem theo mssv---------------------------
        public void t_msv()
        {
            tim_msv = new sinhvien[sosv];
            sinhvien t_msv = new sinhvien();
            string msv;
            Console.Write("NHAP VAO MA SINH VIEN: ");
            msv = Console.ReadLine();
            int dem = 0;
            for (int i = 0; i < sosv; i++)
            {
                if (msv == sv1[i].get_masv())
                {
                    Console.Write("\nSTT:         \t{0}", (i + 1));
                    sv1[i].hienthisv();
                    Console.WriteLine("\n----------------------");
                    dem++;
                }
            }
            Console.WriteLine();
            if (dem == 0) Console.WriteLine("KHONG CO SINH VIEN NAO!");
            Console.WriteLine();
        }
        //-------------------------------MENU HIEN THI-----------------------------------
        public void menu_hthi()
        {
            Console.Clear();
            Console.WriteLine("\t\tHIEN THI");
            Console.WriteLine("NHAN PHIM DE CHON CHUC NANG");
            Console.WriteLine("\t1.   HIEN THI TAT CA SINH VIEN THEO THU TU NHAP");
            Console.WriteLine("\t2.   HIEN THI TAT CA SINH VIEN THEO DIEM TB TANG DAN");
            Console.WriteLine("\t3.   HIEN THI TAT CA SINH VIEN CO DIEM 3 MON TREN 5");
            Console.WriteLine("\t4.   TRO LAI MENU TRUOC");
            Console.WriteLine("\tESC. THOAT CHUONG TRINH");

        }
        //-------------------------------MENU TIM KIEM----------------------------------
        public void menu_timkiem()
        {
            Console.Clear();
            Console.WriteLine("\t\tTIM KIEM");
            Console.WriteLine("NHAN PHIM DE CHON CHUC NANG");
            Console.WriteLine("\t1.   TIM KIEM THEO TEN");
            Console.WriteLine("\t2.   TIM KIEM THEO MSSV");
            Console.WriteLine("\t3.   TIM KIEM THEO XEP LOAI DIEM TB");
            Console.WriteLine("\t4.   TRO LAI MENU TRUOC");
            Console.WriteLine("\tESC. THOAT CHUONG TRINH");

        }
        public void menu_xuatnhap()
        {
            Console.Clear();
            Console.WriteLine("\t\tEXPORT & IMPORT");
            Console.WriteLine("NHAN PHIM DE CHON CHUC NANG");
            Console.WriteLine("\t1.   GHI FILE");
            Console.WriteLine("\t2.   DOC FILE");
            Console.WriteLine("\t3.   TRO LAI MENU TRUOC");
            Console.WriteLine("\tESC. THOAT CHUONG TRINH");

        }
        //--------------------------------MENU TIM KIEM THEO XEP LOAI TB------------------
        public void menu_tim_xl()
        {
            Console.Clear();
            Console.WriteLine("\t\t\tTIM KIEM");
            Console.Clear();
            Console.WriteLine("NHAN PHIM DE CHON CHUC NANG");
            Console.WriteLine("\t1.   YEU:         DTB<5 ");
            Console.WriteLine("\t2.   TRUNG BINH:  5<=DTB<=7 ");
            Console.WriteLine("\t3.   KHA:         7<DTB<=8 ");
            Console.WriteLine("\t4.   GIOI:        8<DTB<=10 ");
            Console.WriteLine("\t5.   TRO LAI MENU TRUOC");
            Console.WriteLine("\tESC. THOAT CHUONG TRINH");
            ConsoleKeyInfo k2;
            k2 = Console.ReadKey();
            tim_xl = new sinhvien[sosv];
            int xl;
            tim_xl = sv1;
            switch (k2.Key)
            {
                case ConsoleKey.D1:
                    {
                        int dem = 0;
                        Console.Clear();
                        Console.WriteLine("\t\tSINH VIEN XEP LOAI YEU");
                        Console.WriteLine();
                        for (int i = 0; i < sosv; i++)
                        {
                            xl = Convert.ToInt16(sv1[i].get_dtb());
                            if (xl < 5)
                            {

                                Console.Write("\nSTT:         \t{0}", (dem + 1));
                                sv1[i].hienthisv();
                                Console.WriteLine("\n----------------------");
                                dem++;
                            }
                        }
                        Console.WriteLine();
                        if (dem == 0) Console.WriteLine("KHONG CO SINH VIEN NAO!");
                        Console.WriteLine();
                        Console.WriteLine("NHAN PHIM BAT KI DE TRO LAI");
                        Console.ReadKey();
                        menu_tim_xl();
                        break;
                    }
                case ConsoleKey.D2:
                    {
                        int dem = 0;
                        Console.Clear();
                        Console.WriteLine("\t\tSINH VIEN XEP LOAI TRUNG BINH");
                        Console.WriteLine();
                        for (int i = 0; i < sosv; i++)
                        {
                            xl = Convert.ToInt16(sv1[i].get_dtb());
                            if ((xl >= 5) && (xl <= 7))
                            {
                                Console.Clear();
                                Console.Write("\nSTT:         \t{0}", (dem + 1));
                                sv1[i].hienthisv();
                                Console.WriteLine("\n----------------------");
                                dem++;
                            }
                        }
                        Console.WriteLine();
                        if (dem == 0) Console.WriteLine("KHONG CO SINH VIEN NAO!");
                        Console.WriteLine();
                        Console.WriteLine("NHAN PHIM BAT KI DE TRO LAI");
                        Console.ReadKey();
                        menu_tim_xl();
                        break;

                    }
                case ConsoleKey.D3:
                    {
                        int dem = 0;
                        Console.Clear();
                        Console.WriteLine("\t\tSINH VIEN XEP LOAI KHA");
                        Console.WriteLine();
                        for (int i = 0; i < sosv; i++)
                        {
                            xl = Convert.ToInt16(sv1[i].get_dtb());
                            if ((xl > 7) && (xl <= 8))
                            {
                                Console.Clear();
                                Console.Write("\nSTT:         \t{0}", (dem + 1));
                                sv1[i].hienthisv();
                                Console.WriteLine("\n----------------------");
                                dem++;
                            }
                        }
                        Console.WriteLine();
                        if (dem == 0) Console.WriteLine("KHONG CO SINH VIEN NAO!");
                        Console.WriteLine();
                        Console.WriteLine("NHAN PHIM BAT KI DE TRO LAI");
                        Console.ReadKey();
                        menu_tim_xl();
                        break;
                    }
                case ConsoleKey.D4:
                    {
                        int dem = 0;
                        Console.Clear();
                        Console.WriteLine("\t\tSINH VIEN XEP LOAI GIOI");
                        Console.WriteLine();
                        for (int i = 0; i < sosv; i++)
                        {
                            xl = Convert.ToInt16(sv1[i].get_dtb());
                            if ((xl > 8) && (xl <= 10))
                            {
                                Console.Clear();
                                Console.Write("\nSTT:         \t{0}", (i + 1));
                                sv1[i].hienthisv();
                                Console.WriteLine("\n----------------------");
                                dem++;
                            }
                        }
                        Console.WriteLine();
                        if (dem == 0) Console.WriteLine("KHONG CO SINH VIEN NAO!");
                        Console.WriteLine();
                        Console.WriteLine("NHAN PHIM BAT KI DE TRO LAI");
                        Console.ReadKey();
                        menu_tim_xl();
                        break;

                    }
                case ConsoleKey.D5: hienthimenu(); break;
                case ConsoleKey.Escape: Environment.Exit(0); break;
                default:
                    {
                        Console.WriteLine("KHONG DUNG KI TU, XIN NHAP LAI!");
                        Console.ReadKey();
                        menu3();
                        break;
                    }
            }
        }
        //-------------------------------HAM GHI FILE------------------------------------
        public void ghi_file()
        {
            string name, filePath;
            Console.Clear();
            Console.WriteLine("\t\tLUU FILE");
            Console.Write("NHAP TEN FILE MUON LUU: ");
            name = Console.ReadLine();
            filePath = "D:\\" + name + ".ttd";
            if (!File.Exists(filePath))
            {
                using (StreamWriter sw = File.CreateText(filePath))
                {
                    for (int i = 0; i < sosv; i++)
                    {
                        sw.WriteLine(sv1[i].get_hoten());
                        sw.WriteLine(sv1[i].get_namsinh());
                        sw.WriteLine(sv1[i].get_masv());
                        sw.WriteLine(sv1[i].get_dtoan());
                        sw.WriteLine(sv1[i].get_dly());
                        sw.WriteLine(sv1[i].get_dhoa());
                        sw.WriteLine(sv1[i].get_dtb());
                    }
                    sw.Close();

                }

                Console.WriteLine("\nLUU FILE THANH CONG VAO DIA CHI: " + filePath + "!");
                Console.WriteLine("NHAN PHIM BAT KI DE TRO LAI!");
                Console.ReadKey();
                hienthimenu();
            }
            else
            {
                Console.Clear();
                Console.WriteLine("\t\tTHONG BAO!");
                Console.WriteLine();
                Console.WriteLine("FILE MUON TAO DA TON TAI!!!");
                Console.WriteLine();
                Console.WriteLine("\tNHAN 1: GHI DE VAO FILE DA TON TAI");
                Console.WriteLine("\tNHAN 2: GHI THEM VAO FILE DA TON TAI");
                Console.WriteLine("\tNHAN 3: GHI MOI VAO FILE KHAC");
                Console.WriteLine("\tNHAN 4: TRO LAI");
                ConsoleKeyInfo k3;
                k3 = Console.ReadKey();
                switch (k3.Key)
                {
                    case ConsoleKey.D1:
                        {
                            using (StreamWriter sw = File.CreateText(filePath))
                            {
                                for (int i = 0; i < sosv; i++)
                                {
                                    sw.WriteLine(sv1[i].get_hoten());
                                    sw.WriteLine(sv1[i].get_namsinh());
                                    sw.WriteLine(sv1[i].get_masv());
                                    sw.WriteLine(sv1[i].get_dtoan());
                                    sw.WriteLine(sv1[i].get_dly());
                                    sw.WriteLine(sv1[i].get_dhoa());
                                    sw.WriteLine(sv1[i].get_dtb());
                                }
                                sw.Close();
                            }

                            Console.WriteLine("LUU FILE THANH CONG VAO DIA CHI: " + filePath + "!");
                            Console.WriteLine("NHAN PHIM BAT KI DE TRO LAI!");
                            Console.ReadKey();
                            hienthimenu();
                            break;
                        }
                    case ConsoleKey.D2:
                        {
                            using (StreamWriter sw = File.AppendText(filePath))
                            {
                                for (int i = 0; i < sosv; i++)
                                {
                                    sw.WriteLine(sv1[i].get_hoten());
                                    sw.WriteLine(sv1[i].get_namsinh());
                                    sw.WriteLine(sv1[i].get_masv());
                                    sw.WriteLine(sv1[i].get_dtoan());
                                    sw.WriteLine(sv1[i].get_dly());
                                    sw.WriteLine(sv1[i].get_dhoa());
                                    sw.WriteLine(sv1[i].get_dtb());
                                }
                                sw.Close();
                            }

                            //Console.Clear();
                            Console.WriteLine("\nLUU THEM DU LIEU THANH CONG VAO FILE TAI DIA CHI: " + filePath + "!");
                            Console.WriteLine("NHAN PHIM BAT KI DE TRO LAI!");
                            Console.ReadKey();
                            hienthimenu();
                            break;
                        }
                    case ConsoleKey.D3:
                        {
                            Console.Clear();
                            ghi_file();
                            break;

                        }
                    case ConsoleKey.D4:
                        {
                            hienthimenu();
                            break;
                        }
                    default:
                        {
                            Console.WriteLine("KHONG DUNG KI TU, XIN NHAP LAI!");
                            Console.ReadKey();
                            menu4();
                            break;
                        }
                }
            }


        }
        public void doc_file()
        {
            ConsoleKeyInfo k3;
            Console.Clear();
            Console.WriteLine();
            Console.WriteLine("\t\tIMPORT FILE");
            Console.WriteLine();
            Console.WriteLine("NHAN PHIM DE CHON CHUC NANG:");
            Console.WriteLine();
            Console.WriteLine("\tNHAN 1.   HIEN THI THONG TIN TRONG FILE");
            Console.WriteLine("\tNHAN 2.   TRO LAI MENU TRUOC");
            Console.WriteLine("\tNHAN ESC. THOAT CHUONG TRINH");
            k3 = Console.ReadKey();
            switch (k3.Key)
            {
                case ConsoleKey.D1:
                    {
                        string name, filePath;
                        Console.Clear();
                        Console.WriteLine();
                        Console.WriteLine("\t\tHIEN THI FILE");
                        Console.WriteLine();
                        Console.WriteLine("CHU Y: CHI CO THE NHAP THEM THONG TIN DUOI DANG DUOI '.ttd' VA NAM TRONG THU MUC GOC D:\\\\");
                        Console.WriteLine("MOI BAN KIEM TRA TRUOC KHI NHAP!");
                        Console.WriteLine();
                        Console.Write("NHAP TEN FILE: ");
                        name = Console.ReadLine();
                        filePath = "D:\\" + name + ".ttd";
                        if (File.Exists(filePath))
                        {
                            Console.Clear();
                            Console.WriteLine("\t\tNOI DUNG FILE " + filePath + " !");
                            Console.WriteLine();
                            int max, i = 0;
                            sv3 = new sinhvien[10000];
                            using (StreamReader sr = File.OpenText(filePath))
                            {
                                string hoten, msv, nsinh, dtoan, dly, dhoa, dtb;
                                while
                                       ((hoten = sr.ReadLine()) != null &&
                                        (msv = sr.ReadLine()) != null &&
                                        (nsinh = sr.ReadLine()) != null &&
                                        (dtoan = sr.ReadLine()) != null &&
                                        (dly = sr.ReadLine()) != null &&
                                        (dhoa = sr.ReadLine()) != null &&
                                        (dtb = sr.ReadLine()) != null)
                                {
                                    sv3[i] = new sinhvien();
                                    sv3[i].set_hoten(hoten);
                                    sv3[i].set_namsinh(int.Parse(nsinh));
                                    sv3[i].set_masv(msv);
                                    sv3[i].set_dtoan(float.Parse(dtoan));
                                    sv3[i].set_dly(float.Parse(dly));
                                    sv3[i].set_dhoa(float.Parse(dhoa));
                                    sv3[i].set_dtb(float.Parse(dtb));
                                    i++;
                                }
                                max = i;
                                Console.WriteLine();
                                for (i = 0; i < max; i++)
                                {
                                    sv3[i].hienthisv();
                                }
                                Console.WriteLine();
                                sr.Close();
                            }
                        }
                        else
                        {
                            Console.Clear();
                            Console.WriteLine();
                            Console.WriteLine("\t\tFILE KHONG TON TAI TREN THU MUC GOC!!");
                            Console.WriteLine();
                            Console.WriteLine("\tNHAN 1. NHAP LAI");
                            Console.WriteLine("\tNHAN 2. TRO LAI");
                            ConsoleKeyInfo k4 = Console.ReadKey();
                            switch (k4.Key)
                            {
                                case ConsoleKey.D1:
                                    {
                                        doc_file();
                                        break;
                                    }
                                case ConsoleKey.D2:
                                    {
                                        hienthimenu();
                                        break;
                                    }
                            }
                        }

                        Console.WriteLine("NHAN NUT BAT KI DE TRO LAI!");
                        Console.ReadKey();
                        menu4();
                        break;
                    }
                case ConsoleKey.D2:
                    {
                        hienthimenu();
                        break;
                    }
                case ConsoleKey.Escape: Environment.Exit(0); break;
                default:
                    {
                        Console.WriteLine("KHONG DUNG KI TU, XIN NHAP LAI!");
                        Console.ReadKey();
                        menu4();
                        break;
                    }

            }
        }
    }
}

